﻿#region Copyright and License
/*==============================================================================
 *  Copyright (c) cndotnet.org Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.cndotnet.org/ezsocio
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CNdotnet.Ezsocio.DataEntities;
using CNdotnet.Ezsocio.BusinessObjects;
using CNdotnet.Ezsocio.Core.Validations;

namespace CNdotnet.Ezsocio.BusinessServices.Extensions
{
    /// <summary>
    /// The extension methods class of message contract
    /// </summary>
    public static class MessageContractExtension
    {
        /// <summary>
        /// Converts to contract.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public static MessageContract ConvertToContract(this Message message)
        {
            ValidationUtility.IsNullValidate<Message>(message);

            MessageContract mc = new MessageContract()
            {
                Content = message.Content,
                FromUser = new AccountService().GetAccountByID(message.FromUserID, true),
                ID = message.ID,
                IsDeleted = message.IsDeleted,
                SentDate = message.SentDate,
                ToUser = new AccountService().GetAccountByID(message.ToUserID, true),
                Type = message.Type,
                IsNew = message.IsNew
            };
            return mc;
        }
    }
}
